package util

import "os"

const (
	PAN_DIR          = ".pan"
	TOKEN_FILENAME   = "token"
	CONFIG_FILENAME  = "config"
	RSA_KEY_FILENAME = "pan.key"
)

const (
	CONF_NAME        = "pan"
	CONF_VERSION     = "1.0.0"
	CONF_DESCRIPTION = "pan is a tool for managing syberos pan"
)

func homePath(file string) (string, error) {
	home, err := os.UserHomeDir()
	if err != nil {
		return "", err
	}
	dir := PathJoin(home, PAN_DIR)
	if !IsExists(dir) {
		if err := os.Mkdir(dir, os.FileMode(0755)); err != nil {
			return "", err
		}
	}
	return PathJoin(dir, file), nil
}

func ConfigFilePath() string {
	file, err := homePath(CONFIG_FILENAME)
	if err != nil {
		return ""
	}
	if !IsExists(file) {
		return ""
	}
	return file
}

func TokenFilePath() string {
	file, err := homePath(TOKEN_FILENAME)
	if err != nil {
		return ""
	}
	return file
}

func RsaKeyFilePath() string {
	file, err := homePath(RSA_KEY_FILENAME)
	if err != nil {
		return ""
	}
	return file
}
